﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace be.metanous.mvvm.core
{
    /// <summary>
    /// This class extends <see cref="T:PropertyChangingEventArgs"/> and
    /// allows for storing the old and new values of the changed property.
    /// </summary>
    public class PropertyChangingNotificationEventArgs : PropertyChangingEventArgs
    {
        
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="PropertyChangingEventArgs"/> class.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property that is associated with this
        /// notification.
        /// </param>
        public PropertyChangingNotificationEventArgs(String propertyName)
            : this(propertyName, null, null)
        {
            // No-op
        }

        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="PropertyChangingEventArgs"/> class.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property that is associated with this
        /// notification.
        /// </param>
        /// <param name="oldValue">The old value.</param>
        /// <param name="newValue">The new value.</param>
        public PropertyChangingNotificationEventArgs(String propertyName,
            Object oldValue, Object newValue)
            : base(propertyName)
        {
            this.oldValue = oldValue;
            this.newValue = newValue;
            this.Cancel = false;
        }

        #endregion // Constructors

        #region Properties

        /// <summary>
        /// Holds the new value of the property.
        /// </summary>
        private Object newValue;

        /// <summary>
        /// Gets the new value of the property.
        /// </summary>
        /// <value>The new value.</value>
        public Object NewValue
        {
            get
            {
                return this.newValue;
            }
        }

        /// <summary>
        /// Holds the old value of the property.
        /// </summary>
        private Object oldValue;

        /// <summary>
        /// Gets the old value of the property.
        /// </summary>
        /// <value>The old value.</value>
        public Object OldValue
        {
            get
            {
                return this.oldValue;
            }
        }

        /// <summary>
        /// Indicates if the handler wishes to cancel the notification
        /// </summary>
        public bool Cancel { get; set; }

        #endregion // Properties
        
    }
}
